package fr.inria.arles.tempManagement.preferencesStore.query;

import java.sql.ResultSet;

/**
 * A Query to authenticate the user.
 */
public class AuthenticateQuery extends AbstractQuery {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.inria.arles.tempManagement.queryProcessor.query.AbstractQuery#execute
	 * (java.lang.String[])
	 */
	@Override
	public String execute(String[] args) throws Exception {
		ResultSet rs = executeQuery(
				"SELECT ID FROM TEMPERATURE WHERE USERNAME=? AND PASSWORD=? AND PARTITION=?",
				args);
		if (rs.next())
			return rs.getLong("ID")+"";
		else
			throw new Exception("Authentication Failed");
	}

}
